

import requests, threading
import random, string, time, base64
import concurrent.futures as porn
from bs4 import BeautifulSoup

from sys import stdout

def randomString(string_length):
  input = string.ascii_lowercase + string.digits
  return ''.join(random.choice(input) for i in range(string_length))


useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62"



def fnc_shit(i):
  s = requests.Session()
  while True:
    ############################################
    headers_8kun = {
      'Upgrade-Insecure-Requests': '1',
      'Origin': 'https://sys.8kun.top',
      'x-requested-with': 'XMLHttpRequest',
      "accept-encoding": "identity",

      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent': useragent,
      'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
      'Referer': 'https://sys.8kun.top/dnsbls_bypass.php',
      'Accept-Language': 'en-US,en;q=0.9',
    }
    r = s.get("https://sys.8kun.top/dnsbls_bypass.php", headers=headers_8kun)

    session_hash=randomString(12)
    json_data = {
      'fn_index': 0,
      'data': [ "te_be_changed" ],
      'action': 'predict',
      'session_hash': session_hash,
    }

    soup = BeautifulSoup(r.text, 'html.parser')
    img = soup.find('image')['src']
    captcha_cookie = soup.find('input',{'class':'captcha_cookie'})['value']
    json_data['data'][0] = img
    ###############################################################################

    

    project_path="pENrknSoysneed/8kun-captcha-trocr"
    r = s.post(f'https://hf.space/embed/{ project_path }/api/predict/', headers={
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0',
    }, json=json_data)
    average_duration = r.json()['average_duration']
    duration = r.json()['duration']
    captcha = r.json()['data'][0]

    # print(captcha_cookie, captcha)
    data = {
      'captcha_text': f'{captcha}',
      'captcha_cookie': f'{captcha_cookie}',
      'tos_agree': 'on'
    }
    r = s.post('https://sys.8kun.top/dnsbls_bypass.php', headers=headers_8kun, data=data)

    if "but the origin server for this website is offline or unreachable" in r.text:
      continue#Continues the loop. Because we got an error
    if "You failed the CAPTCHA" in r.text:
      main.average_duration = average_duration
      main.duration = duration
      # print(f"Captcha failed average_duration:{average_duration}, duration:{duration}")
      main.captchas_failed += 1
      continue#Continues the loop. Because we got an error
    elif "title>Success!</title" in r.text:
      # print("Success!! we solved a captcha!!!!")
      main.captchas_worked += 1
      break#Breaks because, we got a session! #Breaks to "break the while-loop", therefore it will stop the function. and continue with the bot. 

class stats_hub():
  captchas_failed = 0
  captchas_worked = 0
  average_duration = 0
  duration = 0
  
  def stats(self):
    while True:
      
      txt = f"Captchas that worked:{main.captchas_worked}, [-----] Failed:{main.captchas_failed}"
      txt2 = f"Last average_duration:{main.average_duration}, Last (per the submit) duration:{main.duration}"
      
      for x in range(2):#We got two lines
        stdout.write("\x1b[1A\x1b[2K")
      
      stdout.write(txt+"\n")
      stdout.write(txt2+"\n")
      # stdout.write(f"\r{txt}\r{txt2}\r")
      # stdout.write(f"\r{txt2}")
      # stdout.flush()
      # time.sleep(1.2)
      time.sleep(.45)
    print("\n")

  def banner(self):
    base64_message = "ICAgID0vXCAgICAgICAgICAgICAgICAgL1w9DQogICAgLyBcJy5fICAgKFxfLykgICBfLicvIFwNCiAgIC8gLicnLl8nLS0oby5vKS0tJ18uJycuIFwNCiAgLy4nIF8vIHxgJz0vICIgXD0nYHwgXF8gYC5cDQogL2AgLicgYFw7LSwnXF9fXy8nLC07L2AgJy4gJ1wNCi8uLScgamdzICAgYFwoLVYtKS9gICAgICAgIGAtLlwNCmAgICAgICAgICAgICAiICAgIiAgICAgICAgICAgIGA="
    base64_bytes = base64_message.encode('ascii')
    message_bytes = base64.b64decode(base64_bytes)
    BANNER = message_bytes.decode('ascii')
    print(BANNER)
main = stats_hub()
threading.Thread(target=main.banner).start()
threading.Thread(target=main.stats).start()

# # fnc_shit(1)
threads_multithreading = 20
with porn.ThreadPoolExecutor(max_workers=threads_multithreading) as e:
  future = e.map(fnc_shit, list(range(200)))#200-working captchas

